from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from picasso.models import Album, Photo, Thumbnail, Content
from django.conf import settings

if getattr(settings, 'PICASSO_INDEX_ALBUMS', False):
    index_albums = settings.PICASSO_INDEX_ALBUMS
else:
    index_albums = 4

if getattr(settings, 'PICASSO_INDEX_PHOTOS', False):
    index_photos = settings.PICASSO_INDEX_PHOTOS
else:
    index_photos = 8

def index(request):
    albums = Album.objects.all()[:index_albums]
    photos = Photo.objects.all()[:index_photos]
    
    return render_to_response('picasso/index.html',
                              {'albums': albums,
                               'photos': photos},
                              context_instance=RequestContext(request))

def list_albums(request):
    albums = Album.objects.all()
    
    return render_to_response('picasso/list_albums.html',
                              {'albums': albums},
                              context_instance=RequestContext(request))

def view_album(request, album):
    selected_album = get_object_or_404(Album, name=album)
    
    photos = selected_album.photo_set.all()
    
    return render_to_response('picasso/view_album.html',
                              {'album': selected_album,
                               'photos': photos},
                              context_instance=RequestContext(request))

def view_photo(request, photoid):
    selected_photo = get_object_or_404(Photo, photoid=photoid)
    
    return render_to_response('picasso/view_photo.html',
                              {'photo': selected_photo},
                              context_instance=RequestContext(request))